package com.whq.thrift.api.web.admin.db.config;

import java.util.Map;

import org.apache.ibatis.jdbc.SqlBuilder;

public class ErrorCodeProvider {
	public String getSelectRecrodSql(Map<String, Object> parameter) {
		SqlBuilder.BEGIN();
		SqlBuilder.SELECT("*");
		SqlBuilder.FROM("t_error_code");
		if (parameter.get("errorCode") != null) {
			SqlBuilder.WHERE("error_code=#{errorCode}");
		}
		if (parameter.get("businessType") != null) {
			SqlBuilder.WHERE("business_type=#{businessType}");
		}
		if (parameter.get("moduleName") != null) {
			SqlBuilder.WHERE("module_name=#{moduleName}");
		}
		SqlBuilder.ORDER_BY("error_code asc");
		return SqlBuilder.SQL() + " limit #{beginIndex}, #{maxCount}";
	}

	public String getSelectCountSql(Map<String, Object> parameter) {
		SqlBuilder.BEGIN();
		SqlBuilder.SELECT("count(*)");
		SqlBuilder.FROM("t_error_code");
		if (parameter.get("errorCode") != null) {
			SqlBuilder.WHERE("error_code=#{errorCode}");
		}
		if (parameter.get("businessType") != null) {
			SqlBuilder.WHERE("business_type=#{businessType}");
		}
		if (parameter.get("moduleName") != null) {
			SqlBuilder.WHERE("module_name=#{moduleName}");
		}
		return SqlBuilder.SQL();
	}

	public String getUpdateSql(ErrorCode record) {
		SqlBuilder.BEGIN();
		SqlBuilder.UPDATE("t_error_code");
		SqlBuilder.SET("comment=#{comment}");
		SqlBuilder.SET("error_msg=#{errorMsg}");
		SqlBuilder.SET("business_type=#{businessType}");
		SqlBuilder.SET("module_name=#{moduleName}");
		SqlBuilder.SET("developer=#{developer}");
		SqlBuilder.SET("comment=#{comment}");
		SqlBuilder.SET("update_time=#{updateTime}");
		SqlBuilder.WHERE("error_code=#{errorCode}");
		return SqlBuilder.SQL();
	}
	
}
